package com.edocbase.desktop.plugins.mdairy.part;

import org.eclipse.draw2d.BorderLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

import com.edocbase.desktop.lightweight.widgets.ControlFigure;
import com.edocbase.desktop.lightweight.widgets.FigureOwner;
import com.edocbase.desktop.swt.widgets.RichBrowser;

public class BrowserFigure extends FigureOwner {
	private RichBrowser richBrowser;
	private ControlFigure<Composite> browserFigure;

	public BrowserFigure() {
		super();

	}

	public RichBrowser create(String url) {
		setLayoutManager(new BorderLayout());
		Composite bodyControl = crateBody(getOwner(), url);
		browserFigure = new ControlFigure<Composite>();
		browserFigure.setControl(bodyControl);
		add(browserFigure, BorderLayout.CENTER);
		return richBrowser;
	}

	private Composite crateBody(Control parent, String url) {
		if (richBrowser == null) {
			Composite container = (Composite) parent;
			richBrowser = new RichBrowser(container, SWT.NONE);
			if (url != null) {
				richBrowser.setUrl(url);
			}
		}
		return richBrowser.getBrowser();
	}

	public RichBrowser getRichBrowser() {
		return richBrowser;
	}

}
